import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'pressureTestM',
  state: {},
  effects: {
    //获取情景名称列表
    *getSceneNameList({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.getSceneNameList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg);
      }
    },

    //获取前一交易日
    *getTradingDate({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.getTradingDate, payload);
      if (res && res.message == 'success') {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //获取table
    *getTableData({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.getTableData, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg);
      }
    },

    //新增情景设置
    *addScene({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.addScene, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
    //编辑情景设置
    *editScene({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.editScene, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },

    //删除情景设置
    *deleteScene({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureTest.deleteScene, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.msg);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
